/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tv.global.util;
import java.io.IOException;
import javax.faces.application.ViewExpiredException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @author ctrosch
 */
public class ViewExpiredExcepcionFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        try {

            System.out.println("Filtra: ViewExpiredExcepcionFilter");
            chain.doFilter(req, resp);
        } catch (ServletException e) {
            if (e.getRootCause() instanceof ViewExpiredException) {
                req.getRequestDispatcher("/expired.html").forward(req, resp);
            } else {
                throw e;
            }
        }
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
	
    @Override
    public void destroy() {

    }


}


